package JUC;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        // 计数器
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 3; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " Start");
                countDownLatch.countDown(); // 计数器-1
            }, String.valueOf(i)).start();
        }//阻塞等待计数器归零
        for (int i = 1; i <= 3; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + " Start");
                countDownLatch.countDown(); // 计数器-1
            }, String.valueOf(i)).start();
        }//阻塞等待计数器归零
        countDownLatch.await();  //在哪个线程中调用，谁await


        System.out.println(Thread.currentThread().getName() + " End");
    }

}